/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.etop.odbs.dao;

import com.etop.odbs.beans.Document;
import java.util.List;
import org.hibernate.Session;

/**
 *
 * @author cjh
 */
public class DocumentDao extends BaseDao {

    /**
     * 从数据库中获取相应ID的文档
     *
     * @param id
     * @return
     */
    public Document loadDocumentById(int id) {
        String hql = "from Document where id = :id";
        return (Document) this.getSession().createQuery(hql).setParameter("id", id).uniqueResult();
    }

    public List ListDocument() {
        List<Document> documents = this.getSession().createQuery("select doc from Document doc").list();

        return documents;
    }

    /**
     * 往数据库里面写入一条上传记录
     *
     * @param doc
     */
    public void addDocument(Document doc) {
        this.getSession().save(doc);
    }
}
